package response;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/response_demo2")
public class response_demo2 extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        this.doPost(req,resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println("demo2被访问了");
        resp.setContentType("text/html;charset=utf-8");
        //字符流输出数据
//        resp.getWriter().write("<h1>hello</h1>");
        //字节流输出数据
        resp.getOutputStream().write("你好".getBytes("utf-8"));
    }
}
